<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="groupChat.css" rel="stylesheet" type="text/css"/>
    <title>Title</title>
</head>
<body>
<script>
    // 判断浏览器是否支持WebSocket
    var socket;
    if (window.WebSocket) {
        socket = new WebSocket("ws://127.0.0.1:8888/fmms/systemController/groupChat")
        socket.onmessage = function (ev) {
            var rt = document.getElementById("responseText");
            rt.value = rt.value + "\n" + ev.data;
        }

        socket.onclose = function () {
            var rt = document.getElementById("responseText");
            rt.value = rt.value + "\n" + "连接关闭了.."
        }

        socket.onopen = function () {
            document.getElementById("responseText").value = "群聊已开启"
        }
    } else {
        alert("浏览器不支持WebSocket")
    }


    function send(message) {
        if (!window.socket) {
            return
        }
        if (socket.readyState === WebSocket.OPEN) {
            socket.send(message)
        }
    }
</script>
<form onsubmit="return false">
    <div class="chat-container">
        <textarea id="responseText" class="display-style"></textarea>
        <textarea name="message" class="input-style"></textarea>
        <div class="btn-container">
            <input type="button" value="发送消息" onclick="send(this.form.message.value)">
            <input type="button" value="清空内容" onclick="document.getElementById('responseText').value=''">
        </div>
    </div>

</form>
</body>
</html>